#!/bin/sh /etc/rc.common

START=65
NAME=pdnsd
DESC="proxy DNS server"

DAEMON=/usr/sbin/pdnsd
PID_FILE=/var/run/$NAME.pid
CACHEDIR=/var/pdnsd
CACHE=$CACHEDIR/pdnsd.cache

USER=nobody
GROUP=nogroup

start() {
	config_load "pdnsd"
	local enabled
	config_get enabled config enabled
	[ $enabled -eq 0 ] &&{
	stop
	return 0
	}
	
	echo -n "Starting $DESC: $NAME"

	gen_cache

	$DAEMON --daemon -p $PID_FILE
	echo " ."
}

stop() {
		echo -n "Stopping $DESC: $NAME"
		kill `cat $PID_FILE` > /dev/null 2>&1
		rm -rf $PID_FILE
		echo " ."
}

restart() {
		echo "Restarting $DESC: $NAME... "
		stop
		sleep 2
		start
}

gen_cache()
{
		if ! test -f "$CACHE"; then
			mkdir -p `dirname $CACHE`
			echo -n -e "pd13\0\0\0\0" > "$CACHE"
			chown -R $USER.$GROUP $CACHEDIR
		fi
}
